package com.msmall.community.show.action.html;

import com.msmall.base.action.HTMLBaseAction;
import com.msmall.base.util.ConstantDB;
import com.msmall.base.util.ConstantUrl;
import com.msmall.community.show.service.ShowManager;
import com.msmall.community.user.service.UserManager;

public class IndexAction extends HTMLBaseAction{

	private static final long serialVersionUID = 2250528289519920997L;

	private static final Integer SEARCH_TYPE_NICKNAME = 1;
	private static final Integer SEARCH_TYPE_GENDER_AGE = 2;
	private static final String SESSION_SHOW_SEARCH_NICKNAME = "SESSION_SHOW_SEARCH_NICKNAME";
	
	private Integer searchType;//1按昵称 2 按年龄/性别
	
	private String searchNick;//按昵称搜索
	
	private Short gender;
	
	private Integer agesmin;
	private Integer agesmax;
	
	private ShowManager showManager;
	
	private UserManager userManager;
	
	public void setShowManager(ShowManager showManager) {
		this.showManager = showManager;
	}

	public void setUserManager(UserManager userManager) {
		this.userManager = userManager;
	}

	/**
	 * 进入首页, 获得有效用户的信息
	 */
	public String execute(){
		try {
			showManager.getPagination(page, ConstantDB.VOTE_MODULE_TRAVEL, ConstantDB.VOTE_TYPES_POSITIVE);
			page.setUrl(ConstantUrl.HTML_SHOW);
		} catch (Exception e) {
		}
		return SUCCESS;
	}
	
	public String search(){
		if(SEARCH_TYPE_NICKNAME.compareTo(searchType) == 0){
			if(searchNick == null || "".equals(searchNick)){
				searchNick = (String)getFromSession(SESSION_SHOW_SEARCH_NICKNAME);
			}else{
				setToSession(SESSION_SHOW_SEARCH_NICKNAME, searchNick);
			}
			showManager.getPagination(page, searchNick, ConstantDB.VOTE_MODULE_TRAVEL, ConstantDB.VOTE_TYPES_POSITIVE);
			page.setUrl(ConstantUrl.HTML_SHOW_SEARCH + "?searchType=" +SEARCH_TYPE_NICKNAME);
		}else if(SEARCH_TYPE_GENDER_AGE.compareTo(searchType) == 0){
			showManager.getPagination(page, gender, agesmin, agesmax, ConstantDB.VOTE_MODULE_TRAVEL, ConstantDB.VOTE_TYPES_POSITIVE);
			page.setUrl(ConstantUrl.HTML_SHOW_SEARCH + "?searchType=" +SEARCH_TYPE_GENDER_AGE + "&gender="+gender + "&agesmin=" + agesmin + "&agesmax=" +agesmax);
		}
		return SUCCESS;
	}

	public Integer getSearchType() {
		return searchType;
	}

	public void setSearchType(Integer searchType) {
		this.searchType = searchType;
	}

	public Short getGender() {
		return gender;
	}

	public void setGender(Short gender) {
		this.gender = gender;
	}

	public Integer getAgesmin() {
		return agesmin;
	}

	public void setAgesmin(Integer agesmin) {
		this.agesmin = agesmin;
	}

	public Integer getAgesmax() {
		return agesmax;
	}

	public void setAgesmax(Integer agesmax) {
		this.agesmax = agesmax;
	}

	public String getSearchNick() {
		return searchNick;
	}

	public void setSearchNick(String searchNick) {
		this.searchNick = searchNick;
	}
}
